package jmetal.util;

import jmetal.core.SolutionSet;

/**
 * 极值点单例类
 * @author sevn
 *
 */
public class SingletonExtremePoint {
	private static double[] idealPoint;
	private static double[] nadirPoint;
	private static double[] interceptPoint;
	
	private SingletonExtremePoint(){}
	
	public static double[] getIdealPointInstance(SolutionSet solutionSet){
		if(idealPoint==null)
			idealPoint = ExtremumPoint.getIdealPoint(solutionSet);
		else{
			//更新idealPoint
			double[] tempPoint = ExtremumPoint.getIdealPoint(solutionSet);
			for(int i = 0;i<idealPoint.length;i++){
				if(tempPoint[i]<idealPoint[i]){
					idealPoint[i] = tempPoint[i];
				}
			}
		}
		return idealPoint;
	}
	
	public static double[] getNadirPointInstance(SolutionSet solutionSet){
		if(nadirPoint==null)
			nadirPoint = ExtremumPoint.getNadirPoint(solutionSet);
		else{
			//更新idealPoint
			double[] tempPoint = ExtremumPoint.getNadirPoint(solutionSet);
			for(int i = 0;i<nadirPoint.length;i++){
				if(tempPoint[i]<nadirPoint[i]){
					nadirPoint[i] = tempPoint[i];
				}
			}
		}
		return nadirPoint;
	}

	public static void freePoint() {
		idealPoint = null;
		nadirPoint = null;
		interceptPoint = null;
	}
}
